package com.pllandxzx.controller;

import com.pll.pojo.Role;
import com.pllandxzx.dto.ResponseDTO;
import com.pllandxzx.service.RoleService;
import com.pllandxzx.vo.MenuIdsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName：RoleController
 * @Author: 阿⭐
 * @Date: 2025/6/10 10:28
 * @Description: TODO
 */
@Tag(name = "角色管理")
@RestController
@RequestMapping("/role")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @Operation(summary = "角色列表", description = "展示所有角色列表")
    @GetMapping("/list")
    public ResponseDTO getAllRole(){
        return roleService.getAllRole();
    }

    @Operation(summary = "角色权限列表", description = "展示角色所有菜单，并返回树状菜单")
    @GetMapping("/{roleId}/menu")
    public ResponseDTO getRoleMenu(@PathVariable("roleId")long roleId){
        return roleService.getRoleMenu(roleId);
    }

    @Operation(summary = "新增角色", description = "根据填写信息新增角色")
    @PostMapping("/add")
    public ResponseDTO  addRole(@RequestBody Role role){
        return roleService.addRole(role);
    }

    @Operation(summary = "更新角色", description = "根据角色id，更新角色信息")
    @PutMapping("/update")
    public ResponseDTO updateRole(@RequestBody Role role){
        return roleService.updateRole(role);
    }

    @Operation(summary = "删除角色", description = "根据角色id，删除角色")
    @DeleteMapping("/delete/{roleId}")
    public ResponseDTO addRole(@PathVariable("roleId") int roleId){
        return roleService.deleteRole(roleId);
    }

    @Operation(summary = "分配角色权限", description = "根据角色id，分配角色权限")
    @PutMapping("/{roleId}/permission")
    public ResponseDTO updateRolePermission(@PathVariable("roleId") int roleId,@RequestBody MenuIdsVo menuIdsVo){
        System.out.println(menuIdsVo);
        List<Integer> menuIds = menuIdsVo.getMenuIds();
        return roleService.updateRolePermission(roleId, menuIds);
    }

}
